package com.itheima.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 */
@Configuration
public class RabbitMqConfig {

    /**
     *定义队列名称
     */
    public static final String SPRINGBOOT_QUEUE_NAME="springboot_queue_name";

    /**
     *定义交换机名称
     */
    public static final String SPRINGBOOT_FANOUT_EXCHANGE="springboot_fanout_exchange";

    //声明交换机
    @Bean("myExchange")
    public Exchange fanOutExchange(){

        return ExchangeBuilder.fanoutExchange(SPRINGBOOT_FANOUT_EXCHANGE).durable(true).build();
    }

    /**
     *   声明队列
     */
    @Bean("myQueue")
    public Queue getQueue(){
        return QueueBuilder.durable(SPRINGBOOT_QUEUE_NAME).build();
    }

    /**
     *    绑定队列和交换机
     */
    @Bean
    public Binding queueExchange(@Qualifier("myQueue") Queue queue,
                                 @Qualifier("myExchange") Exchange exchange){

        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
